<template>
  <div>

    <h3>请输入分数:</h3>
    <el-form  ref="resultForm"  :model="resultForm" style="margin: 20px 10px;width: 100%" size="default" :rules="rules" >

      <el-form-item label="1" prop="score1" >
        <el-input  v-model="resultForm.score1"></el-input>
      </el-form-item>
      <el-form-item label="2" prop="score2" >
        <el-input  v-model="resultForm.score2"></el-input>
      </el-form-item>

      <el-form-item label="3" prop="score3" >
        <el-input  v-model="resultForm.score3"></el-input>
      </el-form-item>

      <el-form-item label="4" prop="score4" >
        <el-input  v-model="resultForm.score4"></el-input>
      </el-form-item>

      <el-form-item label="5" prop="score5" >
        <el-input  v-model="resultForm.score5"></el-input>
      </el-form-item>

      <el-form-item style="width: 100%" >
        <el-button style="margin-left: 150px" size="large" @click="returnScore">提交</el-button>
      </el-form-item>


    </el-form>
  </div>
</template>

<script>
import request from "@/utils/request";
import {ElMessage} from "element-plus";

export default {
  name: "double",
  props:{
    idx: {
      type: Number,
      default:-1
    },
  },
  created() {
    this.user=JSON.parse(localStorage.getItem("user"))
    this.scoreForm.gameId=JSON.parse(sessionStorage.getItem("gameId"))
  },
  data(){
    return{
      user:{},
      scoreForm:{
        score:"",
        judgeId:"",
        itemId:""
      },

      resultForm:{
        score1:"",
        score2:"",
        score3:"",
        score4:"",
        score5:"",
        allScore:""
      },
      rules:{
        score1: [
          {required:true,message:"请输入分数",trigger:"blur"},
        ],
        score2: [
          {required:true,message:"请输入分数",trigger:"blur"},
        ],
        score3: [
          {required:true,message:"请输入分数",trigger:"blur"},
        ],
        score4: [
          {required:true,message:"请输入分数",trigger:"blur"},
        ],
        score5: [
          {required:true,message:"请输入分数",trigger:"blur"},
        ],
      }
    }
  },
  methods:{
    returnScore(){
      this.resultForm.allScore=Number(this.resultForm.score1) * 0.1 +Number(this.resultForm.score2) * 0.2 +Number(this.resultForm.score3) * 0.3+Number(this.resultForm.score4) * 0.3 +Number(this.resultForm.score5) * 0.1
      this.$refs['resultForm'].validate((valid) =>{
        if (valid){
          // console.log(this.)
          if(this.resultForm.score1<0 || this.resultForm.score1>100 || this.resultForm.score2<0 || this.resultForm.score2>100 || this.resultForm.allScore<0 || this.resultForm.allScore>100
            || this.resultForm.score3<0 || this.resultForm.score3>100 ||this.resultForm.score4<0 || this.resultForm.score4>100 || this.resultForm.score5<0 || this.resultForm.score5>100
          ){
            this.$message.error("分数输入错误")
            return;
          }
          this.scoreForm.score=this.resultForm.allScore
          this.scoreForm.judgeId=this.user.id
          this.scoreForm.itemId=this.idx
          this.scoreForm.judgeId=this.user.id
          this.scoreForm.itemId=this.idx
          console.log(this.scoreForm)
          request.post("/score/returnScore",this.scoreForm).then(res =>{

            if (res.code === 200) {
              ElMessage({
                type: "success",
                message: "提交成功"
              })
            } else {
              ElMessage({
                type: "error",
                message: "提交失败"
              })
            }
          })
        }else{
          return false;
        }
      })


    },
  }
}
</script>

<style scoped>

</style>